package org.example.service.impl;

import org.example.model.Token;
import org.example.service.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.example.service.UserService2;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Optional;

@Service
public class UserServiceImpl2 implements UserService2 {
    @Autowired
    UserService userService;

    @Override
    public String info(String token) {
        System.out.println("info token="+token);
        if(token==null|| token.trim().length()==0){
            return "token not valid";
        }
        Token t = new Token();
        t.setToken(token);
        Optional<Token> res = userService.findByToken(t);
        if(res.isPresent()){
            return res.get().getEmail();
        }
        return "token not valid";
    }
}
